<?php namespace Home\Controller; 

use Hdphp\Controller\Controller;

//测试控制器
class IndexController extends Controller{

	//构造函数
	public function __init()
	{
	}
	
    //动作
    public function index(){
    	if(IS_POST)
		{
			P($_POST);EXIT;
		}
    	//获取所有分类数据
		$cateData = Data::tree(Db::table("category")->get(),"cname");
//		p($cateData);
		View::with('cateData',$cateData);
       View::make();
    }
	/**
	 * 异步调取规格和属性
	 */
	public function ajaxGetAttr()
	{
		//接受post传输的类型id（tid）
		$tid = $_POST['tid'];
		//在类型属性表中根据类型id获得全部数据
		//where("tid",'=',$tid)->where()
		$data = Db::table("typeattr")->where("type_ID",$tid)->get();
		foreach ($data as $key => $value) {
			 $data[$key]['tavalue']=explode(',', $value['tavalue']); 
		}

		View::ajax($data);
	}
	/**
	 * 异步上传
	 */
	 public function ajaxUpload()
	 {
	 	$file = Upload::path("Upload/" . date("ymd"))->make();
		View::ajax($file[0]);
		
	 }
	 /**
	  * 异步删除图片
	  */
	 public function ajaxDelImg()
	 {
	 	
	 	if(unlink($_POST['url']))
		{
			View::ajax(1);
		}else{
			View::ajax(0);
		}
	 }
}
